<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use DateTimeInterface;

class Corpstatistic extends Model
{
    protected $table = 'corp_statistic';
    protected $primaryKey = 'id';

    public static function getCorpStatistic($corp_id,$phase)
    {
        return self::select("corp_id","phase","uv","pv")->where("corp_id",$corp_id)->whereBetween("phase",$phase)->orderBy("id","DESC")->get();
    }

    public static function corpListDetial($openid,$corp_id)
    {
        return self::where("openid",$openid)->where("corp_id",$corp_id)->first();
    }

    public static function corpListUpdate($openid,$corp_id,$name,$avatar,$collect,$location,$address,$notice)
    {
        return self::where("openid",$openid)->where("corp_id",$corp_id)->update(["name"=>$name,"avatar"=>$avatar,"collect"=>$collect,"location"=>$location,"address"=>$address,"notice"=>$notice]);
    }

    public static function corpListCreate($openid,$corp_id,$name,$avatar,$collect,$location,$address,$end_time,$notice)
    {
        return self::insertGetId(["openid"=>$openid,"name"=>$name,"corp_id"=>$corp_id,"avatar"=>$avatar,"collect"=>$collect,"location"=>$location,"address"=>$address,"end_time"=>$end_time,"notice"=>$notice,"created_at"=>time()]);
    }

    public static function corpListDel($openid)
    {
        return self::where("openid",$openid)->update(["status"=>3]);
    }
}